PHP

How to calculate the factorial of a given number using recursion in PHP | PHP programs

How to calculate the factorial of a given number using recursion in PHP | PHP programs

How to calculate the factorial of a given number using recursion in PHP | PHP programs

 We will calculate the factorial of the specified given number. The factorial of 6 is 720. 6! = 6*5*4*3*2*1=720

<?php


function fact($num)
{
    if ($num == 1) return 1;

    return $num * fact($num - 1);
}

$result = fact(6);
echo "Factorial is: " . $result;
?>
TutorialsLink Curator

This is an official account managed by the team TutorialsLink Community